
import config from './config'
// 封装函数
export default function (url, data = {}, method = 'GET') {
    return new Promise((resolve, reject) => {
        wx.request({
            url: config.host + url,
            data,
            method,
            header: {
                cookie: wx.getStorageSync('cookies') ? wx.getStorageSync('cookies').find(item => item.indexOf('MUSIC_U') !== -1) : ''
            },
            success: (res) => {
                // console.log(res)
                if (data.isLogin) {
                    // 去除cookies数据  保存起来  嵌入到请求头中
                    wx.setStorage({
                        key: 'cookies',
                        data: res.cookies
                    });
                }
                resolve(res.data)
            },
            fail: (err) => {
                reject(err)

            },
        });
    })
}